package com.alibaba.wallstreet.uitls;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.alibaba.fastjson.JSON;

public class JSONUtil {

    public static String toJSONString(Object obj) {
        return JSON.toJSONString(obj);
    }

    public static final <T> T parseObject(String text, Class<T> clazz) {
        return JSON.parseObject(text, clazz);
    }
    
    public static List<String> getStringList(Object val){
		if(null == val){
			return null;
		}
		List<String> result = new ArrayList<String>(1);
		result.add(getValue(val));
		return result;
	}
    
    public static Integer getIntValue(Object val){
    	String strVal = getValue(val);
		try {
			return Integer.parseInt(strVal);
		} catch (Exception e) {
			return null;
		}
	}
	
    public static Long getLongValue(Object val){
		String strVal = getValue(val);
		try {
			return Long.parseLong(strVal);
		} catch (Exception e) {
			return null;
		}
	}
	
    public static String getValue(Object val){
		if(null == val){
			return null;
		}
		String valStr = val.toString();
		if(StringUtils.isBlank(valStr)){
			return null;
		}
		return valStr;
	}
}
